package com.leinao.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;

/**
 * webSocket 配置类
 *
 * @author zhong.wang
 * @date 2025/2/6
 */
@EnableWebSocket
@ConditionalOnProperty(prefix = "yudao.websocket", value = "enable", matchIfMissing = true)
@EnableConfigurationProperties(WebSocketProperty.class)
public class WebSocketConfiguration {
    /**
     * 配置webSocket 的连接设置
     * @param webSocketHandler  webSocket 的 处理器
     * @param webSocketProperty webSocket 的 配置属性
     * @return
     */
    @Bean
    public WebSocketConfigurer webSocketConfigurer(WebSocketHandler webSocketHandler,
                                                   WebSocketProperty webSocketProperty) {
        return registry -> registry
                .addHandler(webSocketHandler, webSocketProperty.getPath())
                .setAllowedOrigins("*");
    }




}
